import Layers from "../layers";
import Asserts from "@/lang/core/asserts.js";

class ChartUtils {
    constructor() {
    }


    /**
     * 类名
     *
     * x 轴的数值名称
     * 例：[1月, 2月, 3月]
     *
     * @param chart {Model|any} 标准图标数据
     * @returns {[String]}
     */
    static getClassName(chart) {
        if (chart.classLabels !== undefined) {
            return chart.classLabels;
        } else {
            Asserts.notBlank(chart.className, 'classname is undefined !');
            let names = [];
            let arr = chart.list;
            let n = chart.className;
            for (let i = 0; i < arr.length; i++) {
                names.push(arr[i][n]);
            }
            return names;
        }
    }

    /**
     * 字段名称
     *
     * 例：[水费，电费]
     *
     * @param chart {Model|any} 标准图标数据
     * @returns {[String]}
     */
    static getFieldNames(chart) {
        Asserts.notBlank(chart.fieldLabels, 'classname is undefined !');
        return chart.fieldLabels;
    }

    /**
     * 字段值
     *
     * 获取 x 轴应于的属性值数组
     * 例：每个月的电费 [3, 4, 5]
     *
     * @param chart {Model|any} 标准图标数据
     * @param i     字段序号
     * @returns {[Number|String]}
     */
    static getFieldValues(chart, i) {
        Asserts.notBlank(chart.fieldNames, 'fieldNames is undefined !');
        let data = [];
        let arr = chart.list;
        let n = chart.fieldNames[i];
        for (let i = 0; i < arr.length; i++) {
            data.push(arr[i][n]);
        }
        return data;
    }
}

export default ChartUtils;